
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ## LOAD DATA 
> df<-read.csv("Dataset.csv")
> df<-subset(df, select=c("votes.centered",
+ 			"country",
+ 			"case_id",
+ 			"merged", "dissolved",
+ 			"year_exist",
+ 			"logseats.centered",
+ 		 "government",
+ 			 "EU_parl",
+ 		 "reg_gov",
+ 		 "finance_party_qualify",
+ 		 "efNPP",
+ 	 "elec_coalition", 
+ 	 "indPOL",
+ 	"election_year_dummy",
+ 	"distinctiveness",
+ 	 "insider", 
+ 	 "organisation", 
+ 	 "newfamfirst",
+ 	"OriginNew",
+ 	"post.election.year",	
+ 	"pre.election.year", 
+ 	"seat.product"
+ 	 ))
> 
> 
> df<-na.exclude(df)
> 
> ## DATA PREPARATION
> country<-as.numeric(factor(df$country), levels=unique(df$country))
> party<-as.numeric(factor(df$case_id), levels=unique(df$case_id))
> num.country<-length(unique(country))
> num.party<-length(unique(party))
> 
> 
> Y<-cbind(df$merged, df$dissolved)
> Y<-cbind(ifelse(rowSums(Y)==0,1,0),Y)
> y<-c(sapply(1:nrow(Y), function(i) which(Y[i,]==1)))
> n<-length(y)          
> 
> Matrix.Country<-matrix(0,n,num.country)
> for (i in 1:num.country) Matrix.Country[country==i,i]<-1
> 
> Matrix.Party<-matrix(0,n,num.party)
> for (i in 1:num.party) Matrix.Party[party==i,i]<-1
> 
> 
> 
> Matrix.Outcome<-matrix(0, n, 3)
> for (i in 1:3) Matrix.Outcome[y==i,i]<-1
> 
> 
> 
> df$OriginNew.newfamfirst<-df$OriginNew*df$newfamfirst
> 
> X<-cbind(1, 
+ 	 df$insider, 
+ 	 df$organisation, 
+        df$newfamfirst,
+ 	 df$OriginNew,
+ 	df$OriginNew.newfamfirst, 
+ 	df$votes.centered, 
+ 	 df$logseats.centered,  
+ 	 df$government,
+ 	 df$EU_parl,
+ 	 df$reg_gov,  
+ 	 df$finance_party_qualify,
+ 	 (df$efNPP-mean(df$efNPP))/(2*sd(df$efNPP)),
+ 	 df$elec_coalition, 
+ 	 (df$indPOL-mean(df$indPOL))/(2*sd(df$indPOL)),
+ 	 (df$seat.product-mean(df$seat.product))/(2*sd(df$seat.product)),
+ 	df$election_year_dummy,
+ 	df$post.election.year,	
+ 	df$pre.election.year, 
+ 	df$distinctiveness )
> 
> 
> Matrix.Cov.Beta<-solve(diag(ncol(X))+(6/(pi^2))*crossprod(X))
> 
> 
> 
> ## LOAD THE PACKAGES REQUIRED FOR RCPP AND SOURCE THE .CPP FILE
> library(Rcpp)
> library(RcppArmadillo)
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RcppArmadillo_0.7.100.3.1 Rcpp_1.0.4.6             
> Sys.setenv("PKG_CXXFLAGS"="-std=c++11")
> sourceCpp("Lognormal.cpp")
> 
> 
> ## RUN THE MCMC ALGORITHM AND STORE PARAMETER DRAWS
> out<-mcmc_logit_index (y=matrix(y),
+ t=matrix(df$year_exist),
+ X=as.matrix(X),
+ I_country=as.matrix(Matrix.Country),
+ I_party=as.matrix(Matrix.Party),
+ Cov_Beta=as.matrix(Matrix.Cov.Beta),
+ beta2start=matrix(0, ncol(X)),
+ beta3start=matrix(0, ncol(X)),
+ sigmastart=c(1, 1),
+ reffect_countrystart=matrix(0,ncol(Matrix.Country),2),
+ reffect_partystart=matrix(0,ncol(Matrix.Party),2),
+ densitybeta=rep(0,ncol(X)),
+ DiagWish=diag(2),
+ mcmc=650000,
+ burn=200000,
+ thin=10,
+ chains=3
+ 
+  )
> 
> 
> 
> ## STORE THE PARAMETER DRAWS
> save(out, file="Estimates_Lognormal")
> 
> 
> 
> 
> 
> 
> 
> proc.time()
    user   system  elapsed 
23996.29 48752.18 24259.49 
